import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DepartmentQuery, DepartmentVO, DepartmentForm } from './types';

/**
 * 获取部门树形列表
 *
 * @param queryParams
 */
export function listDepartment(queryParams: DepartmentQuery): AxiosPromise<DepartmentVO[]> {
  return request({
    url: '/api/department',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取部门下拉树形列表
 */
export function listDepartmentOptions(params: any = []): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/department/options',
    method: 'get',
    params: params
  });
}

/**
 * 获取部门表单数据
 *
 * @param id
 */
export function getDepartmentForm(id: number): AxiosPromise<DepartmentForm> {
  return request({
    url: '/api/department/' + id,
    method: 'get'
  });
}

/**
 * 添加部门
 *
 * @param data
 */
export function addDepartment(data: DepartmentForm) {
  return request({
    url: '/api/department',
    method: 'post',
    data: data
  });
}

/**
 * 修改部门
 *
 * @param id
 * @param data
 */
export function updateDepartment(id: string, data: DepartmentForm) {
  return request({
    url: '/api/department/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 删除部门
 *
 * @param id
 */
export function deleteDepartment(id: number) {
  return request({
    url: '/api/department/' + id,
    method: 'delete'
  });
}


/**
 * 获取部门统计
 *
 * @param id
 */
export function departmentStructure() {
  return request({
    url: '/api/department/structure',
    method: 'get'
  });
}


/**
 * 修改部门负责人
 *
 * @param id
 * @param data
 */
export function updateDepartmentLeader(id: string, data: DepartmentForm) {
	return request({
		url: '/api/department/leader/' + id,
		method: 'post',
		data: data
	});
}
